<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Enkuso
 * Date: 12/18/12
 * Time: 4:01 PM
 * To change this template use File | Settings | File Templates.
 */
class sfWidgetFormYearPicker extends sfWidgetFormInput
{
    protected function configure($options = array(), $attributes = array())
    {
        parent::configure($options, $attributes);
        $this->setAttribute('class', 'yearpicker input-small');
    }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        return '<div class="input-append">'
            . parent::render($name, $value, $attributes, $errors)
            . '<span class="add-on"><i class="awe-calendar"></i></span></div>'
            . $this->getJs();
    }
    public function getStylesheets()
    {
        return array(
        );
    }
    public function getJavaScripts()
    {
        return array(
            "/js/plugins/datepicker/bootstrap-datepicker.js",
        );
    }

    private function getJs()
    {
        return <<<EOF
<script>
  $(document).ready(function() {

        $('.yearpicker').datepicker({
          format : "yyyy",
          'startView' : 2
        }).on('changeYear', function(e) {
          var dp = $(e.currentTarget).data('datepicker');
          dp.date = e.date;
          dp.setValue();
          dp.hide();
        });

    });
</script>
EOF;
    }

}
